package com.limh.base.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.limh.base.utils.SizeTransform;
import com.limh.base.widget.ZoomImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * @function：
 * @author： limh
 * @date： 2018/10/31
 * Copyright @2018 Corpration Name
 */
public class ViewPagerAdapter extends PagerAdapter {

    private List<String> images;
    private Context context;

    public ViewPagerAdapter(Context context,List<String> images) {
        this.images = images;
        this.context=context;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ZoomImageView imageView = new ZoomImageView(context);
        ViewGroup.LayoutParams params=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
        imageView.setLayoutParams(params);
        Picasso.get().load(images.get(position)).transform(new SizeTransform()).into(imageView);
        container.addView(imageView);
        return imageView;
    }

    @Override
    public int getCount() {
        return images.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        View view = (View) object;
        container.removeView(view);
    }
}
